package com.owen.client;

import com.google.gwt.core.client.GWT;
import com.google.web.bindery.event.shared.EventBus;
import com.google.web.bindery.event.shared.SimpleEventBus;
import com.google.web.bindery.requestfactory.gwt.client.DefaultRequestTransport;
import com.google.web.bindery.requestfactory.shared.RequestFactory;
import com.google.web.bindery.requestfactory.shared.impl.AbstractRequestFactory;
import com.owen.client.ui.ClassEditorPresenter;
import com.owen.client.ui.ClassPresenter;
import com.owen.client.ui.widget.ClassEditor;
import com.owen.client.ui.widget.ClassWidget;
import com.owen.shared.AppRequestFactory;

public class UIFactoryInstance implements UIFactory {

	private static final EventBus eventBus = new SimpleEventBus();
	private static final AppRequestFactory requestFactory = GWT.create(AppRequestFactory.class);
	
	private static final ClassPresenter bookPresenter = new ClassPresenter(new ClassWidget(), eventBus, requestFactory);
	
	private static UIFactoryInstance instance = null;
	
	public static UIFactoryInstance getInstance() {
		if(instance == null) {

			GWT.log("Instantiating new UIFactoryInstance...");
			
			instance = new UIFactoryInstance();
			requestFactory.initialize(eventBus);
			
		}
		return instance;
	}
	
	@Override
	public EventBus getEventBus() {
		return eventBus;
	}

	@Override
	public RequestFactory getRequestFactory() {
		return requestFactory;
	}

	@Override
	public ClassPresenter getClassPresenter() {
		return bookPresenter;
	}	

}
